<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/2/1
 * Time: 10:42
 */

namespace app\admin\controller\common;
use think\Validate;
use think\Db;
class Yan_zheng
{
    #是否包含特殊字符 是否为字母和数字，下划线_及破折号-
    public function is_string($data)
    {
        $validate = new Validate([
            'name'  => 'require|chsDash'
        ]);
        $data = implode(',',$data);
        $data = explode(',',$data);
        foreach ($data as $index=>$key){
            $data = [
                'name'  => $key
            ];
            if (!$validate->check($data)) {
                return $validate->getError().$index;
            }
            if(count($data) == ($index+1)){
                return 1;
            }
        }
    }

    #数字判断
    public function is_number($int)
    {
        $validate = new Validate([
            'name'  => 'number|require'
        ]);

        foreach ($int as $index=>$key){
            $data = [
                'name'  => $key
            ];
            if (!$validate->check($data)) {
                return $validate->getError();
            }
            if(count($data) == ($index+1)){
                return 1;
            }
        }
    }

    #日志
    public function rizhi($text,$id = 0)
    {
        $da['ip'] = request()->ip();
        $da['text'] = $text;
        $da['index'] = $id;
        $da['admin_id'] = is_null(session('dsihUGJKJOIJiojf*&%$6uig12@#$sdD'))?0:session('dsihUGJKJOIJiojf*&%$6uig12@#$sdD');
        Db::table('q_journal')->insert($da);
    }
}